#include "PlayTurnsMenu.h"
#include "StringUtilities.h"
#include "PrintUtilities.h"
#include "User.h"
#include "League.h"
#include "LeagueManager.h"
#include "MenuManager.h"
#include "Global.h"
#include "People.h"
#include "GamePrintUtils.h"
#include "MatchData.h"

PlayTurnsMenu::PlayTurnsMenu(MenuManager* const i_menuManager)
	: Menu(i_menuManager)
{
}

void PlayTurnsMenu::Draw() const
{
	using namespace STD;

	const LeagueVec& leagues = GetSP()->GetLeagueMgr().GetLeagues(true);
	for (size_t i = 0; i < leagues.size(); ++i)
	{
		cout << endl;
		if (!(GetSP()->GetLeagueMgr().GetCurrentTurn() > leagues[i]->GetCalendar()->GetTurnNumber()))
		{
			const MatchDataVec& currentTurn = leagues[i]->GetLastPlayedTurn();
			for (MatchDataVecCIt It = currentTurn.begin(); It != currentTurn.end(); ++It)
			{
				const MatchData& match = *(*It);
				PrintMatchResult(cout, match, GetSP(), true);
				cout << endl;
				PrintPostMatchEvents(cout, match, GetSP());
			}
		}
		cout << endl;
	}

	cout << Print::Options(" 0) Return to previous menu'") << " Selection: ";
}

bool PlayTurnsMenu::Input(const STL::string& i_input)
{
	bool goodInput = true;

	int res = Utilities::StringToInt(i_input);

	if (res == 0)
		GetMM()->SetMenu(GetMM()->GetMainMenu());
	else 
		goodInput = false;
	
	return goodInput;
}